<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点我</button>
    <script>
        // 要求，直接对函数进行结论，

        // 来一个节流函数，传入需要被处理的函数， 返回被节流之后的函数
        let btn = document.querySelector('button')
        function fn() {
            console.log('开始');
        }
        const throttleFn =  function(fn,duration) {
            var flag= true 
       
            var timer 
            return function() {
                var self = this
                if(flag) {
                    fn.apply(self, arguments)
                    flag = false
                    timer = setTimeout(function() {

                        //虽然结束了，也要清除定时器
                        clearTimeout(timer)
                        timer = null
                        flag = true
                    },duration || 1000)
                } else {
                    return false
                }
            }
        }
        btn.onclick = throttleFn(fn)
    </script>
</body>
</html>